package com.ff.discounts.component.productdetail

import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import androidx.core.content.ContextCompat
import androidx.fragment.app.FragmentManager
import com.ff.discounts.component.rankinglist.AddVideoDialogFragment
import com.ff.discounts.databinding.FragmentDialogBuyBinding
import com.ff.discounts.dialog.BaseViewModelDialogFragment
import com.ff.discounts.library.log.HiLog
import com.ff.discounts.superui.util.ScreenUtil

/**
 * 升级甄选卡
 * @author: fufang
 * @date: 2023/10/27
 */
class BuyDialogFragment : BaseViewModelDialogFragment<FragmentDialogBuyBinding>(){
    override fun initViews() {
        super.initViews()
        // 点击弹窗外面不能关闭
        isCancelable = true



    }

    override fun initDatum() {
        super.initDatum()

    }

    override fun initListeners() {
        super.initListeners()
        binding.buyNow.setOnClickListener {
            dismiss()
            showAuthorization()
        }
        binding.goVip.setOnClickListener {
            HiLog.d("升级甄选卡")
        }
    }

    /**
     * 显示淘宝授权弹窗
     */
    private fun showAuthorization() {
        AuthorizationDialog.show(requireActivity().supportFragmentManager){

        }
    }

    override fun onResume() {
        super.onResume()
        //修改宽度，默认比AlertDialog.Builder显示对话框宽度窄，看着不好看
        //参考：https://stackoverflow.com/questions/12478520/how-to-set-dialogfragments-width-and-height
        val params: ViewGroup.LayoutParams = dialog!!.window!!.attributes
        params.width = ScreenUtil.getScreenWith(requireContext())
        params.height = ViewGroup.LayoutParams.WRAP_CONTENT
        dialog!!.window!!.attributes = params as WindowManager.LayoutParams
        val drawable = ContextCompat.getDrawable(
            requireContext(), com.ff.discounts.R.drawable.shape_empty
        )
        /// 设置内容背景颜色
        dialog?.window?.setBackgroundDrawable(drawable);

    }

    companion object {
        /**
         * 显示对话框
         */
        fun show(fragmentManager: FragmentManager, onAgreementClickListener: View.OnClickListener) {
            val dialogFragment = BuyDialogFragment()


            dialogFragment.show(fragmentManager, "TermServiceDialogFragment")
        }
    }
}